<%@ Page Title="Questions Control Panel" Language="C#" MasterPageFile="~/Views/Shared/Employee.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<DomainModel.Entities.Question>>" %>

<asp:Content ContentPlaceHolderID="TitleContent" runat="server">
	Questions Control Panel
</asp:Content>

<asp:Content ContentPlaceHolderID="MainContent" runat="server">

<% using (Html.BeginForm("Index", "Questions"))
   { %>
   
   <% if (ViewData["error"] != "") {  %>
     <p><label class="staffingexperterror" for="JobTitle"><%= Html.Encode(TempData["error"])%></label></p>
   <% } %>
   
    <h2>Existing Questions</h2>
    
    <table class="staffingexpert" style="width: 650px" cellspacing="0" id="QuestionsTable">
        <thead>
        <tr>
            <th>Question</th>
            <th>Min</th>
            <th>Type</th>
            <th>Actions</th>
        </tr>
        </thead>
        <tbody>     
             <% foreach (var item in Model)
                { %>
             
             <tr>
                <td style="width: 380px; white-space: pre-wrap;"><%= Html.Encode(item.QuestionString)%></td>
                <td style="width: 50px; white-space: pre-wrap;"><%= Html.Encode(item.Minimum_Score)%></td>
                <td style="width: 100px; white-space: pre-wrap;">
                    <% if (item.Question_Type == 1) { %> 
                        <%= Html.Encode("Essay") %> 
                    <% } %> 
                    <% else { %> 
                        <%= Html.Encode("Multiple Choice") %> 
                    <% } %>
                </td>
                <td style="width: 120px">
                    <%= Html.ActionLink("Edit", "EditQuestion", new { item.QuestionID }) %> |
                    <%= Html.ActionLink("Delete", "DeleteQuestion", new { item.QuestionID }) %>
                    <% if (item.Question_Type == 0) { %>
                        <br/><%= Ajax.ActionLink("View Answers", "ViewAnswers", new { item.QuestionID }, new AjaxOptions { UpdateTargetId = "AnswersTableDiv", OnSuccess = "UpdateTable" })%>
                        <br/><%= Html.ActionLink("Attach a new answer", "CreateAnswer", new { item.QuestionID })%>
                    <% } %>
                </td>
            </tr>
            
        <% } %>
        </tbody>
    </table>
    
    <script type="text/javascript">
        function UpdateTable() {
            var t = new ScrollableTable(document.getElementById('AnswersTable'), 103);
        }
    </script>
    
    <script type="text/javascript">
        var t = new ScrollableTable(document.getElementById('QuestionsTable'), 220);
    </script>
    
    <p><%= Html.ActionLink("Add a new question", "CreateQuestion")%></p>
    
    <div id="AnswersTableDiv"><p><% Html.RenderPartial("AnswersTable", ViewData["answers"]); %></p></div>
    
    <% } %>
    
</asp:Content>
